package day20171123;

import java.sql.*;

/**
 * Created by Administrator on 2017-11-23.
 */
public class Test {

    public static void main(String[] args) {


        // 加载驱动程序

        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");


            /**
             *
             *
             */
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test?serverTimezone=UTC",
                    "root",
                    "sctu123456"
            );


            statement = connection.createStatement();

            String sql = "select * from t_users";
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {

                System.out.println(resultSet.getLong(1));
                System.out.println(resultSet.getString(2));
                System.out.println(resultSet.getString(3));
                System.out.println(resultSet.getInt(4));
                System.out.println(resultSet.getString(5));

            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }


        }


    }
}
